#ifndef A_H
#define A_H
#define XYPATH
//-------------------------------------------------------------
#include <vector>
//-------------------------------------------------------------
using namespace std;
//-------------------------------------------------------------
class A
{
public:
	A(int* piLevel, int iLevelWidth, int iLevelHeight);
	~A();

	bool calculatePath(int iOriginCol, int iOriginRow, int iDestinationCol, int iDestinationRow, int* &piPath, size_t& riPathLenght, vector<int> &rkPath);
	void changeLevel(int* piLevel, int iLevelWidth, int iLevelHeight);

private:
	struct Node
	{
		Node* kParent;
		int iCol;
		int	iRow;
		vector<Node*> kAdyacents;
		int iCost;
		int iDistanceFromOrigin;
		int iManhattan;
		int iTotalCost;
	};

	Node* m_kLevel;
	int m_iLevelHeight;
	int m_iLevelWidth;
	vector<Node*> m_kNodosAbiertos;
	vector<Node*> m_kNodosCerrados;

	void calcuteAdyacents(Node* kNode);
	void addAdyToOpenList(int iIndex, int iOriginIndex, int iDestinIndex);
	void removeFromOpenList(int iIndex);
	int searchLowestCost();
	int calculateManhattan(int iIndex, int iDestinIndex);
	int calculateCostFromOrigin(int iIndex, int iOriginIndex, int iParentCost);
	bool isOnOpenList(int iIndex);
	bool isOnClosedList(int iIndex);
	void constructPath(int iDestinIndex, int* &piPath, size_t& riPathLenght, vector<int> &rkPath);
	void constructXYPath(int iDestinIndex, int iDestinationCol, int iDestinationRow, int* &piPath, size_t& riPathLenght, vector<int> &rkPath);
	void resetInfo();

};
//-------------------------------------------------------------
#endif //A_H
//-------------------------------------------------------------
